package com.ruoyi.web.controller.base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PropertyHouse;
import com.ruoyi.system.service.IPropertyHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房屋档案Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/system/house")
public class PropertyHouseController extends BaseController
{
    @Autowired
    private IPropertyHouseService propertyHouseService;

    /**
     * 查询房屋档案列表
     */
    @PreAuthorize("@ss.hasPermi('system:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(PropertyHouse propertyHouse)
    {
        startPage();
        List<PropertyHouse> list = propertyHouseService.selectPropertyHouseList(propertyHouse);
        return getDataTable(list);
    }

    /**
     * 导出房屋档案列表
     */
    @PreAuthorize("@ss.hasPermi('system:house:export')")
    @Log(title = "房屋档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyHouse propertyHouse)
    {
        List<PropertyHouse> list = propertyHouseService.selectPropertyHouseList(propertyHouse);
        ExcelUtil<PropertyHouse> util = new ExcelUtil<PropertyHouse>(PropertyHouse.class);
        util.exportExcel(response, list, "房屋档案数据");
    }

    /**
     * 获取房屋档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:house:query')")
    @GetMapping(value = "/{houseId}")
    public AjaxResult getInfo(@PathVariable("houseId") Long houseId)
    {
        return success(propertyHouseService.selectPropertyHouseByHouseId(houseId));
    }

    /**
     * 新增房屋档案
     */
    @PreAuthorize("@ss.hasPermi('system:house:add')")
    @Log(title = "房屋档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyHouse propertyHouse)
    {
        return toAjax(propertyHouseService.insertPropertyHouse(propertyHouse));
    }

    /**
     * 修改房屋档案
     */
    @PreAuthorize("@ss.hasPermi('system:house:edit')")
    @Log(title = "房屋档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyHouse propertyHouse)
    {
        return toAjax(propertyHouseService.updatePropertyHouse(propertyHouse));
    }

    /**
     * 删除房屋档案
     */
    @PreAuthorize("@ss.hasPermi('system:house:remove')")
    @Log(title = "房屋档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{houseIds}")
    public AjaxResult remove(@PathVariable Long[] houseIds)
    {
        return toAjax(propertyHouseService.deletePropertyHouseByHouseIds(houseIds));
    }
}
